<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.7"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>My Project: Inc/crc_ccitt.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">My Project<span id="projectnumber">&#160;1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.7 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_f93dfce691d792349f1c14ede440e2e6.html">Inc</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">crc_ccitt.h</div></div>
</div><!--header-->
<div class="contents">
<a href="crc__ccitt_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#ifndef __CRC_CCITT_H</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#define __CRC_CCITT_H</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span> </div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span><span class="comment">/*</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="comment"> * This mysterious table is just the CRC of each possible byte. It can be</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="comment"> * computed using the standard bit-at-a-time methods. The polynomial can</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="comment"> * be seen in entry 128, 0x8408. This corresponds to x^0 + x^5 + x^12.</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span><span class="comment"> * Add the implicit x^16, and you have the standard CRC-CCITT.</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span><span class="comment"> * https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/lib/crc-ccitt.c</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="comment"> */</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span>uint16_t <span class="keyword">const</span> crc_ccitt_table[256] = {</div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span>    0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,</div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span>    0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>    0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,</div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span>    0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,</div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span>    0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span>    0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span>    0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span>    0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>    0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>    0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span>    0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>    0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span>    0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span>    0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span>    0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span>    0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>    0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>    0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>    0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>    0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>    0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>    0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>    0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>    0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>    0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span>    0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>    0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span>    0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>    0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>    0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span>    0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>    0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>};</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span> </div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span> </div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span><span class="keyword">static</span> uint16_t crc_ccitt_byte(uint16_t crc, <span class="keyword">const</span> uint8_t c)</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>{</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>    <span class="keywordflow">return</span> (crc &gt;&gt; 8) ^ crc_ccitt_table[(crc ^ c) &amp; 0xff];</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>}</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span> </div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span><span class="keyword">static</span> uint16_t crc_ccitt(uint16_t crc, uint8_t <span class="keyword">const</span> *buffer, <span class="keywordtype">size_t</span> len)</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>{</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>    uint16_t tmp = crc;</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>    <span class="keywordflow">while</span> (len--)</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>        tmp = crc_ccitt_byte(tmp, *buffer++);</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>    <span class="keywordflow">return</span> tmp;</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>}</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span> </div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span> </div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span><span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.7
</small></address>
</body>
</html>
